package com.xiaochao.bigdata.spark.sort


/**
  * 品类二次排序key
  *
  * 封装你要进行排序算法需要的几个字段：点击次数、下单次数和支付次数
  * 实现Ordered接口要求的几个方法
  *
  * 跟其他key相比，如何来判定大于、大于等于、小于、小于等于
  *
  * 依次使用三个次数进行比较，如果某一个相等，那么就比较下一个
  *
  * @author Administrator
  *
  */
class SortKey(val clickCount: Int,
              val orderCount: Int,
              val payCount: Int)
  extends Ordered[SortKey] with Serializable {

  def compare(that: SortKey): Int = {
    if(clickCount - that.clickCount != 0) {
      clickCount - that.clickCount
    } else if(orderCount - that.orderCount != 0) {
      orderCount - that.orderCount
    } else if(payCount - that.payCount != 0) {
      payCount - that.payCount
    } else {
      0
    }
  }

}